﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using PassBag;
using PassBag.Data;
using PassBag.Logic.Settings;

namespace TestPassBag {
    [TestFixture, Description ("Test application settings read write")]
    [Ignore ("Ignore due a bug : C# Application.StartupPath changed by NUnit")]
    public class TestAppSettings {
        private const string OUTPUT_DIRECTORY = "Settings";
        private const string OUTPUT_FILE = "settings.xml";

        [SetUp, Description ("Prepare directory for settings output")]
        public void PrepareOutputDirectory () {
            if (System.IO.Directory.Exists (XmlSettingsManager.SettingDirectory)) {
                System.IO.Directory.Delete (XmlSettingsManager.SettingDirectory, true);
            }
        }

        [Test, Description("Check if setting manager init work with save")]
        public void TestSaveSettings () {
            XmlSettingsManager.Save ();

            Assert.IsTrue (System.IO.File.Exists (XmlSettingsManager.SettingFullFileName));
        }

        [Test, Description ("Check if setting manager create settings file on first access")]
        public void TestCreateBeforeAccessSetting () {
            bool boolValue = XmlSettingsManager.Settings.GeneralClearClipboardOnLock;

          //  Assert.IsTrue (System.IO.File.Exists (XmlSettingsManager.SettingFullFileName));
        }

        [Test, Description ("Check if setting are correctly saved/loaded")]
        public void TestSettingsReadWrite () {
            string testString = "c:\\The lazy dog";
            XmlSettingsManager.Settings.BackupDefaultLinux = testString;
            //XmlSettingsManager.Settings.GeneralLanguage = testString;
            XmlSettingsManager.Save ();
            XmlSettingsManager.Settings.BackupDefaultLinux = string.Empty;

            XmlSettingsManager.ReloadFromFile ();

            Assert.AreEqual (XmlSettingsManager.Settings.BackupDefaultLinux, testString);
            //Assert.AreEqual (XmlSettingsManager.Settings.GeneralLanguage, testString);
        }
    }
}
